package com.ideaction.entity.mail.filter;

import com.ideaction.entity.mail.BaseMail;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import java.util.Map;

/**
 * 一些简单条件的筛选(时间,状态)
 *
 * @author ZGame
 */
@Component
public class MailSimpleFilter extends MailFilter {
    
    @PostConstruct
    public void registNext() {
        this.nextMatch = new ChannelVersionFilter();
    }
    
    @Override
    protected boolean filtJudge(BaseMail mail, Map<String, Integer> mailStatus, String... params) {
        
        if (mail.getEndTime() > 0 && mail.getEndTime() < System.currentTimeMillis()) {
            return true;
        }
        if (!mailStatus.isEmpty()) {
            if (mailStatus.containsKey(mail.get_id())) {
                int personSysStatus = mailStatus.get(mail.get_id());
                if (personSysStatus == DELETE_STATUS) {
                    return true;
                }
                // 设置一下状态给客户端展示
                mail.setStatus(personSysStatus);
            }
        }
        return false;
    }
}
